#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
typedef pair<int,int> PII;
const int N=1010,M=20010;
int f[N][M];
int v[N],w[N],s[N];
int q[M];
int cnt=0;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>v[i]>>w[i]>>s[i];
	
	for(int i=1;i<=n;i++)
	{
	    for(int r=0;r<v[i];r++)
	    {
	        int tail=-1,head=0;
	        for(int j=r;j<=m;j+=v[i])
	        {
	            while(head<=tail && j-q[head]>s[i]*v[i]) head++;
	            while(head<=tail && f[i-1][q[tail]]+(j-q[tail])/v[i]*w[i]<=f[i-1][j]) tail--;
	            q[++tail]=j;
	            f[i][j]=f[i-1][q[head]]+(j-q[head])/v[i]*w[i];
	        }
	    }
	}
	cout<<f[n][m];

	return 0;
}

